package S12.first;

import java.util.*;

public class Organization {
	private int orgId, pid;
	private String name;
	private static final Map<Integer, Organization>map;
	static {
		map=new HashMap<Integer, Organization>();
		String s="1	0	河南水利与环境职业学院\n"
				+ "2	1	信息工程系\n"
				+ "3	1	机电工程系\n"
				+ "4	1	水利工程系系\n"
				+ "5	1	土木工程系\n"
				+ "6	1	经济管理系\n"
				+ "7	1	环境工程系\n"
				+ "8	2	计算机公共基础教研室\n"
				+ "9	2	计算机应用技术教研室\n"
				+ "10	2	大数据人工智能教研室\n"
				+ "11	2	物联网教研室";
		String[] rows = s.split("\n");
		for(String h: rows) {
			String[] its = h.split("\t");
			int orgId= Integer.parseInt(its[0]);
			int pid= Integer.parseInt(its[1]);
			Organization org = new Organization(orgId, pid, its[2]);
			map.put(orgId, org);
		}

	}
	public Organization(int orgId, int pid, String name) {
		this.orgId=orgId;
		this.pid=pid;
		this.name=name;
	}
	public static String getFullOrganizationName(int orgId) {
		Organization org = map.get(orgId);
		if(org==null)return null;
		StringBuilder sb=new StringBuilder(org.name);//该行相当于下面的两行
//		StringBuilder sb=new StringBuilder();
//		sb.append(org.name);
		while(org.pid!=0) {
			org=map.get(org.pid);
			sb.insert(0, org.name);
		}
		return sb.toString();
	}
}
